package com.core.sdk.extra.weather;

import java.lang.reflect.Type;

import org.apache.http.client.methods.HttpUriRequest;

import roboguice.util.RoboAsyncTask;
import android.content.Context;

import com.core.sdk.utils.HttpUtil;
import com.core.sdk.utils.HttpUtil.ParamSendType;
import com.google.gson.reflect.TypeToken;

public class WeatherSimpleLoadTask extends RoboAsyncTask<WeatherSimpleInfo> {
	private final String TAG = this.getClass().getSimpleName();

	private String cityId = null;
	private final String baseUrl = "http://www.weather.com.cn/data/cityinfo/%s.html";

	/*
	 * 2. 图片接口 http://m.weather.com.cn/img/c0.gif
	 * http://m.weather.com.cn/img/b0.gif
	 * http://www.weather.com.cn/m/i/weatherpic/29x20/d0.gif
	 * http://www.weather.com.cn/m2/i/icon_weather/29x20/n00.gif
	 * 这个图就是天气现象0（晴）的图片
	 * ，其他天气现象的图片依此类推。c打头的图片是20*20像素的，b打头的是50*46像素的，d打头的是反白的图标，29
	 * *20像素，n打头的是夜间反白图标，29*20像素，注意这里的文件名是两位数字！ 也许还有更多的图标，等待大家发掘啦~
	 * 
	 */
	public WeatherSimpleLoadTask(Context context, String cityId) {
		super(context);
		this.cityId = cityId;
	}

	@Override
	public WeatherSimpleInfo call() throws Exception {
		String url = String.format(baseUrl, cityId);
		Type type = new TypeToken<WeatherResponse<WeatherSimpleInfo>>() {}.getType();
		HttpUriRequest request = HttpUtil.buildRequest(url, HttpUtil.Method.GET,null,ParamSendType.text);
		WeatherResponse<WeatherSimpleInfo> wr = HttpUtil.execute(request, type);
		return wr.getWeatherinfo();
	}

}
